<?php namespace Admin\Controller;
//品牌控制器
class BrandController extends CommonController{
	private $model;
	public function __auto(){
		$this->model=new \Common\Model\Brand;
	}
	//品牌列表
	public function index(){
		$data=$this->model->orderBy("sort","DESC")->get();
		if(!$data) View::error("品牌列表为空，请先添加品牌",U('add'));
		View::with('data',$data);
	    View::make();
	}
	//添加品牌
	public function add(){
		if(IS_POST){
			if(!$this->model->store()) View::error($this->model->getError());
			View::success("添加成功",U('index'));
		}
	    View::make();
	}
	//编辑类型
	public function edit(){
		if(IS_POST){
			if(!$this->model->edit()) View::error($this->model->getError());
			View::success("修改成功",U('index'));
		}
		$bid=Q('get.bid');
		$oldData=$this->model->where("bid='{$bid}'")->find();
		View::with('oldData',$oldData);
	    View::make();
	}
	//删除分类
	public function del(){
		$bid=Q('get.bid',0,'intval');
		$delImg=$this->model->where("bid='{$bid}'")->lists('logo');
		if($delImg[0]){
			$img=str_replace('_thumb', '', $delImg[0]);
			unlink($delImg[0]);unlink($img);
		}
		$this->model->where("bid='{$bid}'")->delete();
		
		View::success("删除成功");
	}
} 
 ?>